import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

public class Demo1 {
    public static void main(String[] args) throws Exception {
        //工厂实例
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

        //解析器
        DocumentBuilder db = dbf.newDocumentBuilder();

        //解析文件
        Document doc = db.parse("src/收藏信息.xml");

        NodeList brandList= doc.getElementsByTagName("Brand");

        for (int i = 0; i < brandList.getLength(); i++) {
            Node brand = brandList.item(i);
            Element eleBrand=(Element) brand;
            String name = eleBrand.getAttribute("name");

            NodeList childNodess = eleBrand.getElementsByTagName("Type");


            Element eleItem = (Element)childNodess.item(0);
            NodeList titleList = eleItem.getElementsByTagName("title");

            NodeList childNodes = eleBrand.getChildNodes();
            for (int j = 0; j < childNodes.getLength(); j++) {
                Element ele = (Element) childNodes.item(j);
                String name1=ele.getAttribute("name");
                System.out.println(name+":"+name1);
            }
        }
    }
}
